#ifndef PLAYER_H
#define PLAYER_H
#include<QDebug>
#include <QObject>
#include<gamescene.h>
#include<box2d/b2_body.h>
#include<QGraphicsItem>
#include <QMovie>
#include <QLabel>
#include<raycastcontroller.h>

typedef enum {
    moveRight,
    moveLeft,
    jumpUpLeft,
    jumpUpRight,
    jumpLeft,
    jumpRight,
    standLeft,
    standRight,
    jumpingLeft,
    jumpingRight,
    attackRight,
    attackLeft,
    combinationAttackRight,
    combinationAttackLeft,
    defenseRight,
    defenseLeft,
    attackedLeft,
    attackedRight,
    arrack
} PlayerStatus;
class Player : public QObject
{
    Q_OBJECT
public:
    explicit Player(QObject *parent = nullptr);
    ///
    /// \brief Player
    /// \param name 人物名称 p1 p2
    ///
    Player(QString name);
    void run();
    ///
    /// \brief init
    /// \param scene 当前场景
    /// \param name 玩家名字
    ///
    void init();
    ///
    /// \brief 设置人物当前状态，人物状态机提供给外部的一个状态改变函数，外部通过该函数完成状态的更新
    /// \param status 人物状态的枚举类
    ///
    void setStatus(PlayerStatus status);

    ///获取当前人物图像
    QGraphicsPixmapItem* getGraphics();
    void setGraphics(QGraphicsPixmapItem *graphics);

    ///设置人物的物理刚体
    void setBody(b2Body* body);
    ///获取人物当前状态
    PlayerStatus getStatus();
    //获取 人物 分数
    int getScore();
    void setScore(int score);
    //获取技能点
    int getSkillPoint();
    ///清空技能点
    void clearPoint();
    //设置技能点图标
    void setpointLabel1(QLabel *pointLabel1);
    void setpointLabel2(QLabel *pointLabel2);
    void setpointLabel3(QLabel *pointLabel3);


    QLabel *getpointLabel1();
    QLabel *getpointLabel2();
    QLabel *getpointLabel3();
    ///获取受击次数
    int  getAttackedNum();
    ///设置受击次数变化
    void setAttackedNum();
    ///设置行动标志
    void setActionFlag(bool actionFlag);
    ///获得行动标志
    bool getActionFlag();
    ///设置QMovie
    void setMovie(QMovie *movie);
    ///获得QMovie
    QMovie* getMovie();
    ///设置玩家名
    void setPlayerName(QString playerName);
    ///获得玩家名
    QString getPlayerName();

    void setAgainstPlayer(Player *p);

    int getCombinationAttackCD();
    void setAreaActive(bool is);

    // void setStatus();
public slots:


    b2Body*  getBody();

    b2Vec2 getDirection();
    void setRayCast(RayCastController* raycast);


private:
    double x,y;
    double offx,offy;
    QString playerName;
    bool areaActive;
    GameScene* parent;
    b2Body* body;
    PlayerStatus status;
    QGraphicsPixmapItem* graphics;
    QMovie *movie;
    bool actionFlag;
    bool attackFlag;
    ///是否能被攻击
    bool attackedFlag;

    bool flip;
    QTimer *skillGifTimer;
    QTimer *attackGifTimer;
    QTimer *attackedGifTimer;
    QTimer *jumpTimer;
    QTimer* moveTimer;
     QTimer *cdTimer;
    b2Vec2 dir;
    RayCastController* raycast;
    int skillPoint;

    QLabel *pointLabel1;
    QLabel *pointLabel2;
    QLabel *pointLabel3;
    int score;
    ///受击次数
    int attackedNum;
    int attackCD;
    int defenseCD;
    int combinationAttackCD;
    Player* agaistPlayer;

signals:

};

#endif // PLAYER_H
